package cz.salixsoft.bugreporter.adapter.mantis;

import cz.salixsoft.bugreporter.Priority;
import java.math.BigInteger;

/**
 * Converts priority from interface values to mantis values.
 *
 * @author Vrbenský Milan
 * @version 1.0 @created 01-II-2012 15:59:53
 */
class MantisPriorityConverter {

    protected final BigInteger NONE = new BigInteger("10");
    protected final BigInteger LOW = new BigInteger("20");
    protected final BigInteger NORMAL = new BigInteger("30");
    protected final BigInteger HIGH = new BigInteger("40");
    protected final BigInteger URGENT = new BigInteger("50");
    protected final BigInteger IMMEDIATE = new BigInteger("60");

    /**
     * Default priority.
     */
    private BigInteger defaultPriority;

    /**
     * Constructor. Sets the default priority to MEDIUM.
     */
    public MantisPriorityConverter() {
        setDefaultPriority(Priority.MEDIUM);
    }

    /**
     * Returns priority in Mantis application format. Default value is medium.
     *
     * @param priority Priority of issue.
     */
    public BigInteger getPriority(Priority priority) {
        BigInteger mantisPriority;

        switch (priority) {
            case HIGH:
                mantisPriority = this.HIGH;
                break;
            case MEDIUM:
                mantisPriority = this.NORMAL;
                break;
            case LOW:
                mantisPriority = this.LOW;
                break;
            default:
                mantisPriority = defaultPriority;
                break;
        }

        return mantisPriority;
    }

    /**
     * Sets the default priority. Cannot be set to null or Priority.NOT_DEFINED
     * value.
     *
     * @param priority Default priority of bugs.
     */
    public final void setDefaultPriority(Priority priority) {
        if (priority.equals(Priority.NOT_DEFINED)) {
            throw new IllegalArgumentException("Default priority cannot be set do NOT_DEFINED.");
        }

        defaultPriority = getPriority(priority);
    }
}